using System;
using UnityEngine;
using UnityEngine.EventSystems;

public class RichTextUguiImgLinkSupport : MonoBehaviour, IPointerClickHandler
{
    private Action onclickEvent = null;
    public void SetLinkEvent(Action onclick)
    {
        onclickEvent = onclick;
    }

    private string url;
    public void SetLinkStr(string url)
    {
        this.url = url;
    }

    public void Reset()
    {
        this.url = string.Empty;
        onclickEvent = null;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if (onclickEvent != null)
        {
            onclickEvent.Invoke();
            return;
        }

        if (!string.IsNullOrEmpty(url))
        {
            Application.OpenURL(url);
        }
    }
}
